package com.wmb.permissionservice.controller;

import com.wmb.permissionservice.service.UserPermissionService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/permission")
@AllArgsConstructor
public class UserPermissionController {

    private UserPermissionService userPermissionService;

    /**
     * 绑定默认角色
     * @param userId
     * @return
     */
    @GetMapping("/default/role")
    public Integer bindDefaultRole(@RequestParam Long userId) {
        return userPermissionService.bindDefaultRole(userId);
    }

    /**
     * 获取用户当前权限
     * @param userId
     * @return
     */
    @GetMapping("/get/roleId")
    public Integer getRoleId(@RequestParam Long userId) {
        return userPermissionService.getUserRoleId(userId);
    }

    /**
     * 校验当前用户是否有查询权限
     * @param loginUserId
     * @param checkoutId
     * @return
     */
    @GetMapping("/checkout")
    public Boolean permissionCheckout(@RequestParam Long loginUserId, @RequestParam Long checkoutId) {
        return userPermissionService.permissionCheckout(loginUserId, checkoutId);
    }

    /**
     * 修改用户权限 -- superAdmin专用
     * @param userId
     * @param userNewRoleId
     * @return
     */
    @GetMapping("/alter-permission")
    public Integer alterUserPermission(@RequestParam Long userId, @RequestParam String userNewRoleId) {
        return userPermissionService.updateUserRole(userId, userNewRoleId);
    }
}
